import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueDevTools from "vite-plugin-vue-devtools";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
import compression from "vite-plugin-compression";
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    Components({
      resolvers: [
        AntDesignVueResolver({
          importStyle: false, // css in js
        }),
      ],
    }),
    compression({ algorithm: "gzip" }), // 或 'brotli'（更高效但 CPU 开销大）
  ],
  server: {
    port: 50,
    host: "0.0.0.0",
    cors: true,
    proxy: {
      "/api": {
        target: "http://localhost:30/api",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  build: {
    outDir: "front_dist",
    assetsDir: "front_assets",
    chunkSizeWarningLimit: 1500, // 调高 chunk 大小警告阈值
    rollupOptions: {
      output: {
        manualChunks: (id) => {
          if (id.includes("node_modules")) {
            // 把大依赖拆成单独 chunk（如 lodash、element-plus）
            return "vendor";
          }
        },
      },
    },
  },
});
